<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>


<script>

    $().ready(function () {
        $("#cForm").validate({
            onsubmit: true,// 是否在提交是验证
            onfocusout: false,// 是否在获取焦点时验证
            onkeyup: false,// 是否在敲击键盘时验证

            rules: {　　　　//规则
                user: {　　//要对应相对应的input中的name属性
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {　　　　//验证错误信息
                user: {
                    required: "请输入用户名"
                },
                password: {
                    required: "请输入密码"
                }
            },

            submitHandler: function (form) { //通过之后回调//进行ajax传值
                $.ajax({
                    url: "{:U('user/index')}",
                    type: "post",
                    dataType: "json",
                    data: {
                        user: $("#user").val(),
                        password: $("#password").val()
                    },
                    success: function (msg) {
                        //要执行的代码
                    }
                });
            },

            invalidHandler: function (form, validator) {
                return false;
            }
        });
    });

</script>